package com.dhecp.project.flowable.juel;

import com.dhecp.core.utils.SpringBeanUtils;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.flowable.mapper.SysProcessInstanceMapper;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName AuthService
 * @Description 流程中JUEL表达式取用户等
 * @Author alula
 * @Date 2019-11-28 14:26
 */
@Component
public class ActAuthService implements Serializable {

	private static final long serialVersionUID = -1711225544993620404L;

    //获取当前用户
    public  String getCurrentUser(){
        return ShiroUtils.getUserId();
    }

    //获取代理人
    public  String getAssignee(){
        return  "test1";
    }

    //获取候选人
    public List<String> getCandidateUsers(){
        List<String> result = new ArrayList<String>();
        result.add("test1");
        result.add("test2");
        return result;
    }

    /**
     * 获取流程分支判断
     * @param moduleKey
     * @param tableDataId
     * @param currentUserId
     * @param paramType
     * @return
     */
    public Integer getActProcessBranchResult(String moduleKey, String tableDataId, String currentUserId, String paramType){
        Integer result = 0;
        Map<String, Object> params = new HashMap<>();
        params.put("moduleTable", moduleKey);
        params.put("moduleNid", tableDataId);
        params.put("userId", currentUserId);
        params.put("cType", paramType);
        SysProcessInstanceMapper sysProcessInstanceMapper = SpringBeanUtils.getObject(SysProcessInstanceMapper.class);
        result = sysProcessInstanceMapper.findActProcessBranchResult(params);
        return  result;
    }
}
